#include <iostream>
#include <string>
// 包含SpireMS SDK头文件
#include <sms_core.h>


int main(int argc, char *argv[])
{
    sms::mem_init();
    sms::Publisher pub("/share_mem/image", "memory_msgs::RawImage");
    
    cv::Mat img;  // = cv::imread("/home/jario/Pictures/dji_stat_2024-12-30/DJI_20241013165423_0001_V_20241222_000001.jpg");  // cv::Mat::ones(480, 640, CV_8UC3) * 127;
    cv::VideoCapture cap("/home/jario/2024-11-12 13-12-58.mkv");

    int i=0;
    while (1)
    {
        cap >> img;
        if (img.empty())
        {
            cap.set(cv::CAP_PROP_POS_FRAMES, 0);
            continue;
        }
        cv::resize(img, img, cv::Size(1920, 1080));
        nlohmann::json msg = pub.cvimg2sms_mem(img);
        pub.publish(msg);
        sms::msleep(16);
        i++;
        /*
        if (i > 10)
        {
            break;
        }
        */
    }
    size_t total_bytes = img.total() * img.elemSize();
    std::cout << total_bytes << std::endl;
    pub.kill();
    return 0;
}

